﻿using System.Text.Json;
using CapHttp.Core;
using CapHttp.Demo.Shared.Events;
using DotNetCore.CAP;
using Microsoft.AspNetCore.Mvc;

namespace CapHttp.Consumer.Api.Controllers;

[ApiController]
[Route("[controller]/[action]")]
public class TestController : ControllerBase
{
    private readonly ILogger<TestController> _logger;

    public TestController(ILogger<TestController> logger)
    {
        _logger = logger;
    }

    [HttpPost]
    [DistributedEventSubscribe]
    public void Test1([FromBody]Event1 model)
    {
        _logger.LogInformation("Received data: {m}", JsonSerializer.Serialize(model));
    }

    [HttpPost]
    public void Test2()
    {
        
    }

    [HttpPost]
    [DistributedEventSubscribe]
    public void UserCreated(UserCreatedEvent model)
    {
        _logger.LogInformation("Received user id: {id}", model.Id);
    }
}